home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / DocWindow.cpp < prev    next >
Text File  |  1997-02-20  |  4KB  |  169 lines

  1. /*
  2.  *  File:       DocWindow.h
  3.  *  Summary:       Quill's document window.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <->     8/09/96    JDJ        Created
  12.  */
  13.  
  14. #include "DocWindow.h"
  15.  
  16. #include <Map.h>
  17.  
  18. #include <ZMenu.h>
  19. #include <ZMenuBar.h>
  20. #include <ZMiscUtils.h>
  21. #include <ZProfiler.h>
  22.  
  23. #include "Document.h"
  24. #include "ResourceTable.h"
  25.  
  26.  
  27. // ===================================================================================
  28. //    class CDocWindow
  29. // ===================================================================================
  30.  
  31. static TReanimatorRegister<CDocWindow> sDocWindowRegistrar;
  32.  
  33. //---------------------------------------------------------------
  34. //
  35. // CDocWindow::~CDocWindow
  36. //
  37. //---------------------------------------------------------------
  38. CDocWindow::~CDocWindow()
  39. {
  40. }
  41.  
  42.  
  43. //---------------------------------------------------------------
  44. //
  45. // CDocWindow::CDocWindow 
  46. //
  47. //---------------------------------------------------------------
  48. CDocWindow::CDocWindow()
  49. {    
  50. }
  51.  
  52.  
  53. //---------------------------------------------------------------
  54. //
  55. // CDocWindow::Create                                    [static]
  56. //
  57. //---------------------------------------------------------------
  58. MReanimatable* CDocWindow::Create(MReanimatable*)
  59. {
  60.     return new CDocWindow;
  61. }
  62.  
  63. #pragma mark ハ
  64.  
  65. //---------------------------------------------------------------
  66. //
  67. // CDocWindow::OnReanimated
  68. //
  69. //---------------------------------------------------------------
  70. void CDocWindow::OnReanimated()
  71. {
  72.     Inherited::OnReanimated();
  73.     
  74.     CResourceTable* table = dynamic_cast<CResourceTable*>(this->FindSubPane("Resource Table"));
  75.     ASSERT(table != nil);
  76.     this->SetLatentTarget(table);
  77.     
  78.     CCustomClasses* classes = dynamic_cast<CDocument*>(mDoc)->GetCustomPanes();
  79.     classes->AddListener(this);
  80. }
  81.  
  82.  
  83. //---------------------------------------------------------------
  84. //
  85. // CDocWindow::OnActivating
  86. //
  87. //---------------------------------------------------------------
  88. void CDocWindow::OnActivating()
  89. {
  90.     Inherited::OnActivating();
  91.     
  92.     this->UpdateCustomClassMenu();
  93. }
  94.  
  95.  
  96. //---------------------------------------------------------------
  97. //
  98. // CDocWindow::OnBroadcast (SDocumentMessage)
  99. //
  100. //---------------------------------------------------------------
  101. void CDocWindow::OnBroadcast(const SDocumentMessage& mesg)
  102. {
  103.     ASSERT(mesg.document == mDoc);
  104.         
  105.     switch (mesg.change) {
  106.         case kChangedDocument:
  107.             // do nothing
  108.             break;
  109.             
  110.         case kOpenedDocument:
  111.         case kSavedDocument:
  112.         case kRevertedDocument:
  113.             this->Invalidate();
  114.             // fall through
  115.         
  116.         default:
  117.             Inherited::OnBroadcast(mesg);
  118.     }
  119. }
  120.  
  121.  
  122. //---------------------------------------------------------------
  123. //
  124. // CDocWindow::OnBroadcast (CCustomClasses*)
  125. //
  126. //---------------------------------------------------------------
  127. void CDocWindow::OnBroadcast(CCustomClasses* const& mesg)
  128. {
  129.     #pragma unused(mesg)
  130.     
  131.     if (TDocWindow::GetFront() == this)
  132.         this->UpdateCustomClassMenu();
  133. }
  134.  
  135. #pragma mark ハ
  136.  
  137. //---------------------------------------------------------------
  138. //
  139. // CDocWindow::UpdateCustomClassMenu
  140. //
  141. //---------------------------------------------------------------
  142. void CDocWindow::UpdateCustomClassMenu()
  143. {
  144.     TMenu* menu = TMenuBar::Instance()->GetMenuByID(248);
  145.     ASSERT(menu != nil);
  146.     
  147.     // Remove the old items.
  148.     while (menu->GetCount() > 2)
  149.         menu->RemoveItem(0);
  150.     
  151.     // Add the new items.
  152.     CCustomClasses* classes = dynamic_cast<CDocument*>(mDoc)->GetCustomPanes();
  153.     if (classes->GetNumClasses() > 0) {
  154.         menu->InsertItem("(-", 0, kNothingCmd);
  155.         
  156.         const CCustomClasses::ClassTable* table = classes->GetTable();
  157.         CCustomClasses::ClassTable::const_iterator iter = table->begin();
  158.         while (iter != table->end()) {
  159.             CCustomClasses::ClassEntry entry = *iter++;
  160.             
  161.             menu->InsertSortedItem(entry.first, 0, menu->GetCount() - 3, entry.first);
  162.         }
  163.     }    
  164.     
  165.     TMenuBar::Invalidate();
  166. }
  167.  
  168.  
  169.